/*
 * Cache.java
 *
 * Created on August 17, 2006, 11:48 AM
 *
 */

package galronnlp.perceptron;

import galronnlp.util.Tuple;

/**
 *
 * @author Daniel A. Galron
 */
public class Cache {
    
    Tuple[] cache;
    
    /** Creates a new instance of Cache */
    public Cache(int N) {
        cache = new Tuple[N];
    }
    
    public void add(int k, Node g, ParserStack F, boolean fullF) {
        Tuple tup = new Tuple(4);
        tup.put(0, g);
        tup.put(1, F);
        tup.put(2, new Integer(0));
        tup.put(3, new Boolean(fullF));
        cache[k] = tup;
    }

    public void add(int k, Node g, ParserStack F, boolean fullF, int count) {
        Tuple tup = new Tuple(4);
        tup.put(0, g);
        tup.put(1, F);
        tup.put(2, new Integer(count));
        tup.put(3, new Boolean(fullF));
        cache[k] = tup;
    }    
    
    public Node get(int k) {
        return (Node)cache[k].get(0);
    }
    
    public Node getBestParse(int k) {
        return (Node)((ParserStack)cache[k].get(k)).pop();
    }
    
    public void update(int k) {
        cache[k].put(2, ((Integer)cache[k].get(2)).intValue() + 1);
        ((ParserStack)cache[k].get(1)).resort();
    }
    
    public int count(int k) {
        return ((Integer)cache[k].get(2)).intValue();
    }
    
    public boolean isFull(int k) {
        return ((Boolean)cache[k].get(3)).booleanValue();
    }
    
    
}
